<?php
class ContactNumberValidator extends CValidator {

    public $pattern = '/^([0-9 ()\/\-#+])+$/'; // numbers, spaces or ()/-# characters only

    /**
     * Validates the attribute of the object.
     * If there is any error, the error message is added to the object.
     * @param CModel $object the object being validated
     * @param string $attribute the attribute being validated
     */

    protected function validateAttribute($object, $attribute) {
        if (!empty($object->$attribute) && !preg_match($this->pattern, $object->$attribute)) {
            $this->addError($object, $attribute, '{attribute} Only numbers or ()/-# characters are allowed.');
        }
    }

}//end class